]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appDisplay: Simplify loading Folder apps a bit
authorJonas Dreßler <verdre@v0yd.nl>
Fri, 24 Jun 2022 17:25:24 +0000 (19:25 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 1 Feb 2023 12:56:28 +0000 (12:56 +0000)
Instead of plugging into _redisplay(), we can use _loadApps() for this.
It's actually exactly what _loadApps() is meant for...

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2348>

js/ui/appDisplay.js

index 91c428a0798ab4db127bb2e64b8ec55e35bf58c2..a9b876e317f658e76b96fcac674bb92e7d974651 100644 (file)
@@ -2137,7 +2137,7 @@ class FolderView extends BaseAppView {
         this._scrollView.add_action(action);
 
         this._deletingFolder = false;
-        this._appIds = [];
+        this._apps = [];
         this._redisplay();
     }
 
@@ -2145,48 +2145,8 @@ class FolderView extends BaseAppView {
         return new FolderGrid();
     }
 
-    _getFolderApps() {
-        const appIds = [];
-        const excludedApps = this._folder.get_strv('excluded-apps');
-        const appSys = Shell.AppSystem.get_default();
-        const addAppId = appId => {
-            if (excludedApps.includes(appId))
-                return;
-
-            if (this._appFavorites.isFavorite(appId))
-                return;
-
-            const app = appSys.lookup_app(appId);
-            if (!app)
-                return;
-
-            if (!this._parentalControlsManager.shouldShowApp(app.get_app_info()))
-                return;
-
-            if (appIds.indexOf(appId) !== -1)
-                return;
-
-            appIds.push(appId);
-        };
-
-        const folderApps = this._folder.get_strv('apps');
-        folderApps.forEach(addAppId);
-
-        const folderCategories = this._folder.get_strv('categories');
-        const appInfos = this._parentView.getAppInfos();
-        appInfos.forEach(appInfo => {
-            let appCategories = _getCategories(appInfo);
-            if (!_listsIntersect(folderCategories, appCategories))
-                return;
-
-            addAppId(appInfo.get_id());
-        });
-
-        return appIds;
-    }
-
     _getItemPosition(item) {
-        const appIndex = this._appIds.indexOf(item.id);
+        const appIndex = this._apps.indexOf(item.app);
 
         if (appIndex === -1)
             return [-1, -1];
@@ -2196,8 +2156,8 @@ class FolderView extends BaseAppView {
     }
 
     _compareItems(a, b) {
-        const aPosition = this._appIds.indexOf(a.id);
-        const bPosition = this._appIds.indexOf(b.id);
+        const aPosition = this._apps.indexOf(a.app);
+        const bPosition = this._apps.indexOf(b.app);
 
         if (aPosition === -1 && bPosition === -1)
             return a.name.localeCompare(b.name);
@@ -2243,27 +2203,52 @@ class FolderView extends BaseAppView {
     }
 
     _loadApps() {
-        let apps = [];
-        let appSys = Shell.AppSystem.get_default();
+        this._apps = [];
+        const excludedApps = this._folder.get_strv('excluded-apps');
+        const appSys = Shell.AppSystem.get_default();
+        const addAppId = appId => {
+            if (excludedApps.includes(appId))
+                return;
+
+            if (this._appFavorites.isFavorite(appId))
+                return;
 
-        this._appIds.forEach(appId => {
             const app = appSys.lookup_app(appId);
+            if (!app)
+                return;
 
-            let icon = this._items.get(appId);
-            if (!icon)
-                icon = new AppIcon(app);
+            if (!this._parentalControlsManager.shouldShowApp(app.get_app_info()))
+                return;
+
+            if (this._apps.indexOf(app) !== -1)
+                return;
+
+            this._apps.push(app);
+        };
+
+        const folderApps = this._folder.get_strv('apps');
+        folderApps.forEach(addAppId);
+
+        const folderCategories = this._folder.get_strv('categories');
+        const appInfos = this._parentView.getAppInfos();
+        appInfos.forEach(appInfo => {
+            let appCategories = _getCategories(appInfo);
+            if (!_listsIntersect(folderCategories, appCategories))
+                return;
 
-            apps.push(icon);
+            addAppId(appInfo.get_id());
         });
 
-        return apps;
-    }
+        let items = [];
+        this._apps.forEach(app => {
+            let icon = this._items.get(app.get_id());
+            if (!icon)
+                icon = new AppIcon(app);
 
-    _redisplay() {
-        // Keep the app ids list cached
-        this._appIds = this._getFolderApps();
+            items.push(icon);
+        });
 
-        super._redisplay();
+        return items;
     }
 
     acceptDrop(source) {